home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / pao / towns / paolib / vram.asm < prev    next >
Assembly Source File  |  1991-10-18  |  14KB  |  443 lines

  1. ;==============================================================================
  2. ;    << 386ASM V2.0 >>  for  FM TOWNS
  3. ;==============================================================================
  4. .386p
  5.         PAGE        60,132
  6.         NAME        VRAMWRITE
  7.         TITLE        VRAM PUT Strings
  8. ;==============================================================================
  9. ;    VRAMに文字列を書く(16色,480line)
  10. ;
  11. ;    CREATE : 1990.06.01
  12. ;    FINISH : 1990.06.02
  13. ;
  14. ;    < High C からの呼出形式 >
  15. ;    ---------------------------------------------------------------------------
  16. ;    『VRAM書き込みページ設定』
  17. ;    extern    int    VRAM_page( int page ) ;
  18. ;    page : 書き込みページ(0 or 1)
  19. ;
  20. ;    VRAM_page( page ) ;
  21. ;    ---------------------------------------------------------------------------
  22. ;    『VRAM描画色設定』
  23. ;    extern    int    VRAM_color( int fcol,int bcol ) ;
  24. ;    fcol : 文字色(0~15)
  25. ;    bcol : 背景色(0~15)
  26. ;
  27. ;    VRAM_color( fcol,bcol ) ;
  28. ;    ---------------------------------------------------------------------------
  29. ;    『VRAM文字列書き込み』
  30. ;    extern    int VRAM_putstr( int x,int y,char *s ) ;
  31. ;    x,y  : 書き込み開始位置(文字左下座標をドットで示す. x=0~1015, y=0~503)
  32. ;    *s   : 文字列先頭アドレス
  33. ;    ただし、x は 8の倍数に限ります.
  34. ;
  35. ;    VRAM_putstr( x,y,"文字列" ) ;
  36. ;    ---------------------------------------------------------------------------
  37. ;
  38. ;    < note > : TABS = 4
  39. ;
  40. ;    < History >
  41. ;    1990.06.01 : CREATE
  42. ;    1991.04.28 : 清書
  43. ;
  44. ;    Programmed by Y.Hirata ( Nifty-ID : NAB03321 )
  45. ;==============================================================================
  46. ;
  47. INCLUDE    hc.inc                                ;
  48. ;
  49. CGROUP    GROUP pmcode, CODE                    ;
  50. DGROUP    GROUP pmdata, DATA                    ;
  51. ;
  52. ;--------------------------------------------
  53.         public    VRAM_page                    ; VRAM書き込みページ設定
  54.         public    VRAM_color                    ; VRAM描画色設定
  55.         public    VRAM_putstr                    ; 文字列をVRAMに描く
  56. ;--------------------------------------------
  57. ;
  58. ;////////////////////////////////////////////
  59. ;            ネイティブ部
  60. ;////////////////////////////////////////////
  61. ;
  62. ;============================================
  63. ;    定数定義
  64. ;============================================
  65. DOTPVLINE        EQU        512                    ;  512ドット/1垂直ライン
  66. DOTPHLINE        EQU        512                    ; 1024ドット/1水平ライン (4ビット/ピクセル)
  67. XCDOT            EQU        8                    ; 横 8ドット
  68. YCDOT            EQU        16                    ; 縦16ドット
  69. ;
  70. ;********************************************
  71. ;    データ領域
  72. ;********************************************
  73. ;
  74. DATA    SEGMENT                                ;
  75. ;
  76. page_offset        DD        0                    ; 書き込みページのオフセット
  77. font_data        DB        32 dup(?)            ; 漢字/ANKフォント格納領域
  78. color_table        DD        256 dup(?)            ; VRAM描画色テーブル
  79. color_pattern    DD        000000000h,0F0000000h,00F000000h,0FF000000h
  80.                 DD        000F00000h,0F0F00000h,00FF00000h,0FFF00000h
  81.                 DD        0000F0000h,0F00F0000h,00F0F0000h,0FF0F0000h
  82.                 DD        000FF0000h,0F0FF0000h,00FFF0000h,0FFFF0000h
  83.                 DD        00000F000h,0F000F000h,00F00F000h,0FF00F000h
  84.                 DD        000F0F000h,0F0F0F000h,00FF0F000h,0FFF0F000h
  85.                 DD        0000FF000h,0F00FF000h,00F0FF000h,0FF0FF000h
  86.                 DD        000FFF000h,0F0FFF000h,00FFFF000h,0FFFFF000h
  87.                 DD        000000F00h,0F0000F00h,00F000F00h,0FF000F00h
  88.                 DD        000F00F00h,0F0F00F00h,00FF00F00h,0FFF00F00h
  89.                 DD        0000F0F00h,0F00F0F00h,00F0F0F00h,0FF0F0F00h
  90.                 DD        000FF0F00h,0F0FF0F00h,00FFF0F00h,0FFFF0F00h
  91.                 DD        00000FF00h,0F000FF00h,00F00FF00h,0FF00FF00h
  92.                 DD        000F0FF00h,0F0F0FF00h,00FF0FF00h,0FFF0FF00h
  93.                 DD        0000FFF00h,0F00FFF00h,00F0FFF00h,0FF0FFF00h
  94.                 DD        000FFFF00h,0F0FFFF00h,00FFFFF00h,0FFFFFF00h
  95.                 DD        0000000F0h,0F00000F0h,00F0000F0h,0FF0000F0h
  96.                 DD        000F000F0h,0F0F000F0h,00FF000F0h,0FFF000F0h
  97.                 DD        0000F00F0h,0F00F00F0h,00F0F00F0h,0FF0F00F0h
  98.                 DD        000FF00F0h,0F0FF00F0h,00FFF00F0h,0FFFF00F0h
  99.                 DD        00000F0F0h,0F000F0F0h,00F00F0F0h,0FF00F0F0h
  100.                 DD        000F0F0F0h,0F0F0F0F0h,00FF0F0F0h,0FFF0F0F0h
  101.                 DD        0000FF0F0h,0F00FF0F0h,00F0FF0F0h,0FF0FF0F0h
  102.                 DD        000FFF0F0h,0F0FFF0F0h,00FFFF0F0h,0FFFFF0F0h
  103.                 DD        000000FF0h,0F0000FF0h,00F000FF0h,0FF000FF0h
  104.                 DD        000F00FF0h,0F0F00FF0h,00FF00FF0h,0FFF00FF0h
  105.                 DD        0000F0FF0h,0F00F0FF0h,00F0F0FF0h,0FF0F0FF0h
  106.                 DD        000FF0FF0h,0F0FF0FF0h,00FFF0FF0h,0FFFF0FF0h
  107.                 DD        00000FFF0h,0F000FFF0h,00F00FFF0h,0FF00FFF0h
  108.                 DD        000F0FFF0h,0F0F0FFF0h,00FF0FFF0h,0FFF0FFF0h
  109.                 DD        0000FFFF0h,0F00FFFF0h,00F0FFFF0h,0FF0FFFF0h
  110.                 DD        000FFFFF0h,0F0FFFFF0h,00FFFFFF0h,0FFFFFFF0h
  111.                 DD        00000000Fh,0F000000Fh,00F00000Fh,0FF00000Fh
  112.                 DD        000F0000Fh,0F0F0000Fh,00FF0000Fh,0FFF0000Fh
  113.                 DD        0000F000Fh,0F00F000Fh,00F0F000Fh,0FF0F000Fh
  114.                 DD        000FF000Fh,0F0FF000Fh,00FFF000Fh,0FFFF000Fh
  115.                 DD        00000F00Fh,0F000F00Fh,00F00F00Fh,0FF00F00Fh
  116.                 DD        000F0F00Fh,0F0F0F00Fh,00FF0F00Fh,0FFF0F00Fh
  117.                 DD        0000FF00Fh,0F00FF00Fh,00F0FF00Fh,0FF0FF00Fh
  118.                 DD        000FFF00Fh,0F0FFF00Fh,00FFFF00Fh,0FFFFF00Fh
  119.                 DD        000000F0Fh,0F0000F0Fh,00F000F0Fh,0FF000F0Fh
  120.                 DD        000F00F0Fh,0F0F00F0Fh,00FF00F0Fh,0FFF00F0Fh
  121.                 DD        0000F0F0Fh,0F00F0F0Fh,00F0F0F0Fh,0FF0F0F0Fh
  122.                 DD        000FF0F0Fh,0F0FF0F0Fh,00FFF0F0Fh,0FFFF0F0Fh
  123.                 DD        00000FF0Fh,0F000FF0Fh,00F00FF0Fh,0FF00FF0Fh
  124.                 DD        000F0FF0Fh,0F0F0FF0Fh,00FF0FF0Fh,0FFF0FF0Fh
  125.                 DD        0000FFF0Fh,0F00FFF0Fh,00F0FFF0Fh,0FF0FFF0Fh
  126.                 DD        000FFFF0Fh,0F0FFFF0Fh,00FFFFF0Fh,0FFFFFF0Fh
  127.                 DD        0000000FFh,0F00000FFh,00F0000FFh,0FF0000FFh
  128.                 DD        000F000FFh,0F0F000FFh,00FF000FFh,0FFF000FFh
  129.                 DD        0000F00FFh,0F00F00FFh,00F0F00FFh,0FF0F00FFh
  130.                 DD        000FF00FFh,0F0FF00FFh,00FFF00FFh,0FFFF00FFh
  131.                 DD        00000F0FFh,0F000F0FFh,00F00F0FFh,0FF00F0FFh
  132.                 DD        000F0F0FFh,0F0F0F0FFh,00FF0F0FFh,0FFF0F0FFh
  133.                 DD        0000FF0FFh,0F00FF0FFh,00F0FF0FFh,0FF0FF0FFh
  134.                 DD        000FFF0FFh,0F0FFF0FFh,00FFFF0FFh,0FFFFF0FFh
  135.                 DD        000000FFFh,0F0000FFFh,00F000FFFh,0FF000FFFh
  136.                 DD        000F00FFFh,0F0F00FFFh,00FF00FFFh,0FFF00FFFh
  137.                 DD        0000F0FFFh,0F00F0FFFh,00F0F0FFFh,0FF0F0FFFh
  138.                 DD        000FF0FFFh,0F0FF0FFFh,00FFF0FFFh,0FFFF0FFFh
  139.                 DD        00000FFFFh,0F000FFFFh,00F00FFFFh,0FF00FFFFh
  140.                 DD        000F0FFFFh,0F0F0FFFFh,00FF0FFFFh,0FFF0FFFFh
  141.                 DD        0000FFFFFh,0F00FFFFFh,00F0FFFFFh,0FF0FFFFFh
  142.                 DD        000FFFFFFh,0F0FFFFFFh,00FFFFFFFh,0FFFFFFFFh
  143. ; ↑ イメージデータのMSB-LSBを逆にした形(面倒だなぁ・・・)
  144. ;
  145. DATA    ENDS                                ;
  146. ;
  147. ;********************************************
  148. ;    文字列のVRAMへの直接書き込み
  149. ;********************************************
  150. ;
  151. pmcode    SEGMENT                                ;
  152.         ASSUME    cs:CGROUP, ds:DGROUP        ;
  153.                                             ;
  154. ;
  155. ;------------------------------------------------------------------------------
  156. ;    漢字の1バイト目か? ((0x81 <= c && c <= 0x9F) || (0xE0 <= && c <= 0xFC))
  157. ;    < INPUT  > : AL - 文字コード
  158. ;    < RETURN > : 漢字の1バイト目ならばキャリーフラグクリア
  159. ;                 漢字の1バイト目でなければキャリーフラグセット
  160. ;------------------------------------------------------------------------------
  161.         ALIGN    4                            ; dword boundary
  162. iskanji1:
  163.             cmp        al,081h                    ;
  164.             jb        short next1                ;
  165.             cmp        al,09Fh                    ;
  166.             ja        short next1                ;
  167.             clc                                ; キャリーフラグクリア
  168.             ret                                ;
  169. next1:                                        ;
  170.             cmp        al,0E0h                    ;
  171.             jb        short notkanji1            ;
  172.             cmp        al,0FCh                    ;
  173.             ja        short notkanji1            ;
  174.             clc                                ; キャリーフラグクリア
  175.             ret                                ;
  176. notkanji1:                                    ;
  177.             stc                                ; キャリーフラグセット
  178.             ret                                ;
  179. ;
  180. ;------------------------------------------------------------------------------
  181. ;    漢字の2バイト目か? ((0x40 <= c && c <= 0x7E) || (0x80 <= && c <= 0xFC))
  182. ;    < INPUT  > : AL - 文字コード
  183. ;    < RETURN > : 漢字の2バイト目ならばキャリーフラグクリア
  184. ;                 漢字の2バイト目でなければキャリーフラグセット
  185. ;------------------------------------------------------------------------------
  186.         ALIGN    4                            ; dword boundary
  187. iskanji2:
  188.             cmp        al,040h                    ;
  189.             jb        short next2                ;
  190.             cmp        al,07Eh                    ;
  191.             ja        short next2                ;
  192.             clc                                ; キャリーフラグクリア
  193.             ret                                ;
  194. next2:                                        ;
  195.             cmp        al,080h                    ;
  196.             jb        short notkanji2            ;
  197.             cmp        al,0FCh                    ;
  198.             ja        short notkanji2            ;
  199.             clc                                ; キャリーフラグクリア
  200.             ret                                ;
  201. notkanji2:                                    ;
  202.             stc                                ; キャリーフラグセット
  203.             ret                                ;
  204. ;
  205. ;------------------------------------------------------------------------------
  206. ;    書き込みページ設定
  207. ;    < INPUT  > : 第一引数 - 書き込みページ(0 or 1)
  208. ;------------------------------------------------------------------------------
  209.         ALIGN    4                            ; dword boundary
  210. VRAM_page    PROC    NEAR                    ;
  211. #WPAGE        EQU    (dword PTR [ebp+8])            ; 書き込みページ
  212. ;
  213.             push    ebp                        ;
  214.             mov        ebp,esp                    ; スタックフレーム形成
  215. ;
  216.             cmp        #WPAGE,ZERO                ;
  217.             jne        page1                    ;
  218.             xor        eax,eax                    ;
  219.             mov        page_offset,eax            ;
  220.                                             ; page 0
  221.             jmp        short endpage            ;
  222. page1:
  223.             mov        eax,DOTPHLINE            ;
  224.             shl        eax,9                    ; 512ドット / 縦1ライン
  225.             mov        page_offset,eax            ;
  226.                                             ; page 1
  227. ;
  228. endpage:                                    ;
  229.             xor        eax,eax                    ; RETURN = 0
  230. ;
  231.             pop        ebp                        ; スタックフレーム開放
  232.             ret                                ;
  233. VRAM_page    ENDP                            ;
  234. ;
  235. ;------------------------------------------------------------------------------
  236. ;    VRAM描画色設定
  237. ;    < INPUT  > : 第一引数 - 文字色( 0~15 )
  238. ;               : 第二引数 - 背景色( 0~15 )
  239. ;------------------------------------------------------------------------------
  240.         ALIGN    4                            ; dword boundary
  241. VRAM_color    PROC    NEAR                    ;
  242. #FCOL        EQU    (dword PTR [ebp+8])            ; 文字色
  243. #BCOL        EQU    (dword PTR [ebp+12])        ; 背景色
  244. ;
  245.             push    ebp                        ;
  246.             mov        ebp,esp                    ; スタックフレーム形成
  247. ;
  248.             push    es                        ;
  249.             push    esi                        ; レジスタ退避
  250.             push    edi                        ;
  251.             push    edx                        ;
  252.             push    ecx                        ;
  253.             cld                                ;
  254. ;
  255.             mov        eax,#FCOL                ; 4 bit -> 4 byte
  256.             mov        edx,#BCOL                ; 4 bit -> 4 byte
  257.             mov        ecx,7                    ; dword分
  258. ptnset:                                        ;
  259.             shl        eax,4                    ;
  260.             shl        edx,4                    ;
  261.             or        eax,#FCOL                ;
  262.             or        edx,#BCOL                ;
  263.             loop    ptnset                    ;
  264.             mov        #FCOL,eax                ;
  265.             mov        #BCOL,edx                ;
  266. ;
  267.             push    ds                        ;
  268.             pop        es                        ; es = ds
  269.             mov        esi,OFFSET color_pattern; 組合せ
  270.             mov        edi,OFFSET color_table    ; 色パターン格納先
  271.             mov        ecx,256                    ; 全パターン(8bit)
  272. colset:                                        ;
  273.             lodsd                            ; パターン取得
  274.             mov        edx,eax                    ;
  275.             not        edx                        ; 反転
  276.             and        eax,#FCOL                ; 文字色
  277.             and        edx,#BCOL                ; 背景色
  278.             or        eax,edx                    ; 色パターン作成
  279.             stosd                            ;
  280.             loop    colset                    ;
  281. ;
  282.             pop        ecx                        ; レジスタ復元
  283.             pop        edx                        ;
  284.             pop        edi                        ;
  285.             pop        esi                        ;
  286.             pop        es                        ;
  287.             xor        eax,eax                    ; RETURN = 0
  288. ;
  289.             pop        ebp                        ; スタックフレーム開放
  290.             ret                                ;
  291. VRAM_color    ENDP                            ;
  292. ;
  293. ;------------------------------------------------------------------------------
  294. ;    文字列をVRAMに描く
  295. ;    < INPUT  > : 第一引数 - 書き込み位置(X座標)
  296. ;               : 第二引数 - 書き込み位置(Y座標)
  297. ;               : 第三引数 - 文字列ポインタ
  298. ;------------------------------------------------------------------------------
  299.         ALIGN    4                            ; dword boundary
  300. VRAM_putstr    PROC    NEAR                    ;
  301. #WPOSX        EQU    (dword PTR [ebp+8])            ; X座標
  302. #WPOSY        EQU    (dword PTR [ebp+12])        ; Y座標
  303. #STRADR        EQU    (dword PTR [ebp+16])        ; 文字列ポインタ
  304. ;
  305. #writep        EQU    (dword PTR [ebp-4])            ; 次の文字書き込み位置
  306. ;
  307.             push    ebp                        ;
  308.             mov        ebp,esp                    ; スタックフレーム形成
  309.             sub        esp,4                    ; ローカル変数分確保
  310. ;
  311.             push    gs                        ; レジスタ退避
  312.             push    fs                        ;
  313.             push    es                        ;
  314.             push    ds                        ;
  315.             push    edi                        ;
  316.             push    esi                        ;
  317.             push    edx                        ;
  318.             push    ecx                        ;
  319.             push    ebx                        ;
  320. ;
  321.             mov        ax,VRAMSEG1                ;
  322.             mov        es,ax                    ; es = VRAMセレクタ
  323.             mov        ax,ds                    ;
  324.             mov        fs,ax                    ;
  325.             mov        gs,ax                    ; gs = fs = ds
  326. ;
  327.             mov        edi,#WPOSX                ; 書き込み位置計算
  328.             shr        edi,1                    ; / 2
  329.             mov        eax,#WPOSY                ;
  330.             shl        eax,9                    ; 1024ドット / 1ライン ( 512byte )
  331.             add        edi,eax                    ;
  332.             or        edi,page_offset            ;
  333.             mov        #writep,edi                ; 書き込み位置セット
  334. ;
  335. putstart:                                    ;
  336.             cld                                ; 増加
  337.             mov        esi,#STRADR                ; 文字列ポインタ
  338.             lodsb                            ; 文字 -> al
  339.             or        al,al                    ; 文字列終了?
  340.             jz        endstr                    ; 後処理へ
  341. ;
  342.             call    iskanji1                ; 漢字の1バイト目?
  343.             jc        putank                    ;
  344. ;
  345.             xchg    al,ah                    ; al <-> ah
  346.             lodsb                            ; 次の文字 -> al
  347.             or        al,al                    ;
  348.             jz        endstr                    ; 文字列終了!
  349. ;
  350.             call    iskanji2                ; 漢字の2バイト目?
  351.             jc        putank                    ;
  352. putkanji:                                    ;
  353.             mov        #STRADR,esi                ; 次の文字のポインタ
  354.             mov        bx,ax                    ; 文字 -> BX
  355. ;            mov        ax,0200h                ; ah=02h,al=00h
  356.             TBIOS    FNT_BIOS,0200h            ; sjis -> jis (BX->BX)
  357.             mov        dx,1010h                ; 16*16
  358.             mov        esi,OFFSET gs:font_data    ;
  359. ;            mov        ax,0100h                ; ah=01h,al=00h
  360.             TBIOS    FNT_BIOS,0100h            ; 漢字フォント読出 (DS:ESI)
  361. ;
  362.             mov        edi,#writep                ; 書き込み位置
  363. ;
  364.             mov        ebx,OFFSET gs:color_table
  365.                                             ; 色パターンアドレス
  366.             xor        ecx,ecx                    ; ecx = 0 (Left Pattern)
  367.             xor        edx,edx                    ; edx = 0 (Right Pattern)
  368.             add        esi,31                    ; フォントデータを逆に読むため
  369. ;
  370. ; 386はジャンプ命令がない方が速いからREPTを使う.
  371. ;
  372.             REPT    YCDOT                    ;
  373.                 std                            ; データが上下反転しているのに注意
  374.                 lodsb                        ; 漢字フォント(Right Pattern)取り出し
  375.                 movzx    edx,al                ;
  376.                 lodsb                        ; 漢字フォント(Left Pattern)取り出し
  377.                 movzx    ecx,al                ;
  378.                 cld                            ;
  379.                 mov        eax,gs:[ebx+ecx*4]    ; Left Pattern
  380.                 stosd                        ; VRAMへ転送
  381.                 mov        eax,gs:[ebx+edx*4]    ; Right Pattern
  382.                 stosd                        ; VRAMへ転送
  383.                 sub        edi,8                ; 次の文字書き込み位置
  384.                 sub        edi,DOTPHLINE        ;
  385.             ENDM                            ;
  386.             add        #writep,8                ; 書き込み位置更新
  387.             push    gs                        ;
  388.             pop        ds                        ; DS復元
  389. ;
  390.             jmp        putstart                ;
  391. ;
  392. putank:                                        ;
  393.             mov        #STRADR,esi                ; 次の文字のポインタ
  394.             mov        bl,al                    ; ANK -> BL
  395.             mov        dx,0810h                ; 8*16
  396.             mov        esi,OFFSET gs:font_data    ;
  397. ;            xor        ax,ax                    ; ah=00h
  398.             TBIOS    FNT_BIOS,0000h            ; ANKフォント読出 (DS:ESI)
  399. ;
  400.             mov        edi,#writep                ; 書き込み位置
  401. ;
  402.             mov        ebx,OFFSET gs:color_table
  403.                                             ; 色パターンアドレス
  404.             xor        ecx,ecx                    ; ecx = 0
  405.             add        esi,15                    ; フォントデータを逆に読むため
  406. ;
  407.             std                                ; データが上下反転しているのに注意
  408.             REPT    YCDOT                    ;
  409.                 lodsb                        ; ANKフォント取り出し
  410.                 movzx    ecx,al                ;
  411.                 mov        eax,gs:[ebx+ecx*4]    ; 色パターン取得
  412.                 stosd                        ; VRAMへ転送
  413.                 add        edi,4                ; 次の文字書き込み位置
  414.                 sub        edi,DOTPHLINE        ;
  415.             ENDM                            ;
  416.             add        #writep,4                ; 書き込み位置更新
  417.             push    gs                        ;
  418.             pop        ds                        ; DS復元
  419. ;
  420.             jmp        putstart                ;
  421. ;
  422. endstr:                                        ;
  423.             pop        ebx                        ; レジスタ復元
  424.             pop        ecx                        ;
  425.             pop        edx                        ;
  426.             pop        esi                        ;
  427.             pop        edi                        ;
  428.             pop        ds                        ;
  429.             pop        es                        ;
  430.             pop        fs                        ;
  431.             pop        gs                        ;
  432.             xor        eax,eax                    ; RETURN = 0
  433. ;
  434.             add        esp,4                    ; ローカル変数分開放
  435.             pop        ebp                        ; スタックフレーム開放
  436.             ret                                ;
  437. VRAM_putstr    ENDP                            ;
  438. ;
  439. pmcode        ENDS                            ;
  440. ;
  441.         END
  442.  
  443.